// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <ExtrudeStackedAttributes.h>
#include <DataNode.h>

//
// Enum conversion methods for ExtrudeStackedAttributes::VariableDisplayType
//

static const char *VariableDisplayType_strings[] = {
"NodeHeight", "CellHeight", "VariableIndex",
"OriginalData"};

std::string
ExtrudeStackedAttributes::VariableDisplayType_ToString(ExtrudeStackedAttributes::VariableDisplayType t)
{
    int index = int(t);
    if(index < 0 || index >= 4) index = 0;
    return VariableDisplayType_strings[index];
}

std::string
ExtrudeStackedAttributes::VariableDisplayType_ToString(int t)
{
    int index = (t < 0 || t >= 4) ? 0 : t;
    return VariableDisplayType_strings[index];
}

bool
ExtrudeStackedAttributes::VariableDisplayType_FromString(const std::string &s, ExtrudeStackedAttributes::VariableDisplayType &val)
{
    val = ExtrudeStackedAttributes::NodeHeight;
    for(int i = 0; i < 4; ++i)
    {
        if(s == VariableDisplayType_strings[i])
        {
            val = (VariableDisplayType)i;
            return true;
        }
    }
    return false;
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::ExtrudeStackedAttributes
//
// Purpose:
//   Init utility for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void ExtrudeStackedAttributes::Init()
{
    axis[0] = 0;
    axis[1] = 0;
    axis[2] = 1;
    byVariable = true;
    variableDisplay = OriginalData;
    length = 1;
    steps = 1;
    preserveOriginalCellNumbers = true;

    ExtrudeStackedAttributes::SelectAll();
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::ExtrudeStackedAttributes
//
// Purpose:
//   Copy utility for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void ExtrudeStackedAttributes::Copy(const ExtrudeStackedAttributes &obj)
{
    axis[0] = obj.axis[0];
    axis[1] = obj.axis[1];
    axis[2] = obj.axis[2];

    byVariable = obj.byVariable;
    defaultVariable = obj.defaultVariable;
    scalarVariableNames = obj.scalarVariableNames;
    visualVariableNames = obj.visualVariableNames;
    extentMinima = obj.extentMinima;
    extentMaxima = obj.extentMaxima;
    extentScale = obj.extentScale;
    variableDisplay = obj.variableDisplay;
    length = obj.length;
    steps = obj.steps;
    preserveOriginalCellNumbers = obj.preserveOriginalCellNumbers;

    ExtrudeStackedAttributes::SelectAll();
}

// Type map format string
const char *ExtrudeStackedAttributes::TypeMapFormatString = EXTRUDESTACKEDATTRIBUTES_TMFS;
const AttributeGroup::private_tmfs_t ExtrudeStackedAttributes::TmfsStruct = {EXTRUDESTACKEDATTRIBUTES_TMFS};


// ****************************************************************************
// Method: ExtrudeStackedAttributes::ExtrudeStackedAttributes
//
// Purpose:
//   Default constructor for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ExtrudeStackedAttributes::ExtrudeStackedAttributes() :
    AttributeSubject(ExtrudeStackedAttributes::TypeMapFormatString)
{
    ExtrudeStackedAttributes::Init();
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::ExtrudeStackedAttributes
//
// Purpose:
//   Constructor for the derived classes of ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ExtrudeStackedAttributes::ExtrudeStackedAttributes(private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    ExtrudeStackedAttributes::Init();
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::ExtrudeStackedAttributes
//
// Purpose:
//   Copy constructor for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ExtrudeStackedAttributes::ExtrudeStackedAttributes(const ExtrudeStackedAttributes &obj) :
    AttributeSubject(ExtrudeStackedAttributes::TypeMapFormatString)
{
    ExtrudeStackedAttributes::Copy(obj);
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::ExtrudeStackedAttributes
//
// Purpose:
//   Copy constructor for derived classes of the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ExtrudeStackedAttributes::ExtrudeStackedAttributes(const ExtrudeStackedAttributes &obj, private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    ExtrudeStackedAttributes::Copy(obj);
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::~ExtrudeStackedAttributes
//
// Purpose:
//   Destructor for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ExtrudeStackedAttributes::~ExtrudeStackedAttributes()
{
    // nothing here
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::operator =
//
// Purpose:
//   Assignment operator for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

ExtrudeStackedAttributes&
ExtrudeStackedAttributes::operator = (const ExtrudeStackedAttributes &obj)
{
    if (this == &obj) return *this;

    ExtrudeStackedAttributes::Copy(obj);

    return *this;
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::operator ==
//
// Purpose:
//   Comparison operator == for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ExtrudeStackedAttributes::operator == (const ExtrudeStackedAttributes &obj) const
{
    // Compare the axis arrays.
    bool axis_equal = true;
    for(int i = 0; i < 3 && axis_equal; ++i)
        axis_equal = (axis[i] == obj.axis[i]);

    // Create the return value
    return (axis_equal &&
            (byVariable == obj.byVariable) &&
            (defaultVariable == obj.defaultVariable) &&
            (scalarVariableNames == obj.scalarVariableNames) &&
            (visualVariableNames == obj.visualVariableNames) &&
            (extentMinima == obj.extentMinima) &&
            (extentMaxima == obj.extentMaxima) &&
            (extentScale == obj.extentScale) &&
            (variableDisplay == obj.variableDisplay) &&
            (length == obj.length) &&
            (steps == obj.steps) &&
            (preserveOriginalCellNumbers == obj.preserveOriginalCellNumbers));
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::operator !=
//
// Purpose:
//   Comparison operator != for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ExtrudeStackedAttributes::operator != (const ExtrudeStackedAttributes &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::TypeName
//
// Purpose:
//   Type name method for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

const std::string
ExtrudeStackedAttributes::TypeName() const
{
    return "ExtrudeStackedAttributes";
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::CopyAttributes
//
// Purpose:
//   CopyAttributes method for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ExtrudeStackedAttributes::CopyAttributes(const AttributeGroup *atts)
{
    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const ExtrudeStackedAttributes *tmp = (const ExtrudeStackedAttributes *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::CreateCompatible
//
// Purpose:
//   CreateCompatible method for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
ExtrudeStackedAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new ExtrudeStackedAttributes(*this);
    // Other cases could go here too.

    return retval;
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::NewInstance
//
// Purpose:
//   NewInstance method for the ExtrudeStackedAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
ExtrudeStackedAttributes::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new ExtrudeStackedAttributes(*this);
    else
        retval = new ExtrudeStackedAttributes;

    return retval;
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::SelectAll
//
// Purpose:
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
ExtrudeStackedAttributes::SelectAll()
{
    Select(ID_axis,                        (void *)axis, 3);
    Select(ID_byVariable,                  (void *)&byVariable);
    Select(ID_defaultVariable,             (void *)&defaultVariable);
    Select(ID_scalarVariableNames,         (void *)&scalarVariableNames);
    Select(ID_visualVariableNames,         (void *)&visualVariableNames);
    Select(ID_extentMinima,                (void *)&extentMinima);
    Select(ID_extentMaxima,                (void *)&extentMaxima);
    Select(ID_extentScale,                 (void *)&extentScale);
    Select(ID_variableDisplay,             (void *)&variableDisplay);
    Select(ID_length,                      (void *)&length);
    Select(ID_steps,                       (void *)&steps);
    Select(ID_preserveOriginalCellNumbers, (void *)&preserveOriginalCellNumbers);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: ExtrudeStackedAttributes::CreateNode
//
// Purpose:
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ExtrudeStackedAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    ExtrudeStackedAttributes defaultObject;
    bool addToParent = false;
    // Create a node for ExtrudeStackedAttributes.
    DataNode *node = new DataNode("ExtrudeStackedAttributes");

    if(completeSave || !FieldsEqual(ID_axis, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("axis", axis, 3));
    }

    if(completeSave || !FieldsEqual(ID_byVariable, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("byVariable", byVariable));
    }

    if(completeSave || !FieldsEqual(ID_defaultVariable, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("defaultVariable", defaultVariable));
    }

    if(completeSave || !FieldsEqual(ID_scalarVariableNames, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("scalarVariableNames", scalarVariableNames));
    }

    if(completeSave || !FieldsEqual(ID_visualVariableNames, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("visualVariableNames", visualVariableNames));
    }

    if(completeSave || !FieldsEqual(ID_extentMinima, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("extentMinima", extentMinima));
    }

    if(completeSave || !FieldsEqual(ID_extentMaxima, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("extentMaxima", extentMaxima));
    }

    if(completeSave || !FieldsEqual(ID_extentScale, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("extentScale", extentScale));
    }

    if(completeSave || !FieldsEqual(ID_variableDisplay, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("variableDisplay", VariableDisplayType_ToString(variableDisplay)));
    }

    if(completeSave || !FieldsEqual(ID_length, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("length", length));
    }

    if(completeSave || !FieldsEqual(ID_steps, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("steps", steps));
    }

    if(completeSave || !FieldsEqual(ID_preserveOriginalCellNumbers, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("preserveOriginalCellNumbers", preserveOriginalCellNumbers));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::SetFromNode
//
// Purpose:
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
ExtrudeStackedAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("ExtrudeStackedAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("axis")) != 0)
        SetAxis(node->AsDoubleArray());
    if((node = searchNode->GetNode("byVariable")) != 0)
        SetByVariable(node->AsBool());
    if((node = searchNode->GetNode("defaultVariable")) != 0)
        SetDefaultVariable(node->AsString());
    if((node = searchNode->GetNode("scalarVariableNames")) != 0)
        SetScalarVariableNames(node->AsStringVector());
    if((node = searchNode->GetNode("visualVariableNames")) != 0)
        SetVisualVariableNames(node->AsStringVector());
    if((node = searchNode->GetNode("extentMinima")) != 0)
        SetExtentMinima(node->AsDoubleVector());
    if((node = searchNode->GetNode("extentMaxima")) != 0)
        SetExtentMaxima(node->AsDoubleVector());
    if((node = searchNode->GetNode("extentScale")) != 0)
        SetExtentScale(node->AsDoubleVector());
    if((node = searchNode->GetNode("variableDisplay")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 4)
                SetVariableDisplay(VariableDisplayType(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            VariableDisplayType value;
            if(VariableDisplayType_FromString(node->AsString(), value))
                SetVariableDisplay(value);
        }
    }
    if((node = searchNode->GetNode("length")) != 0)
        SetLength(node->AsDouble());
    if((node = searchNode->GetNode("steps")) != 0)
        SetSteps(node->AsInt());
    if((node = searchNode->GetNode("preserveOriginalCellNumbers")) != 0)
        SetPreserveOriginalCellNumbers(node->AsBool());
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
ExtrudeStackedAttributes::SetAxis(const double *axis_)
{
    axis[0] = axis_[0];
    axis[1] = axis_[1];
    axis[2] = axis_[2];
    Select(ID_axis, (void *)axis, 3);
}

void
ExtrudeStackedAttributes::SetByVariable(bool byVariable_)
{
    byVariable = byVariable_;
    Select(ID_byVariable, (void *)&byVariable);
}

void
ExtrudeStackedAttributes::SetDefaultVariable(const std::string &defaultVariable_)
{
    defaultVariable = defaultVariable_;
    Select(ID_defaultVariable, (void *)&defaultVariable);
}

void
ExtrudeStackedAttributes::SetScalarVariableNames(const stringVector &scalarVariableNames_)
{
    scalarVariableNames = scalarVariableNames_;
    Select(ID_scalarVariableNames, (void *)&scalarVariableNames);
}

void
ExtrudeStackedAttributes::SetVisualVariableNames(const stringVector &visualVariableNames_)
{
    visualVariableNames = visualVariableNames_;
    Select(ID_visualVariableNames, (void *)&visualVariableNames);
}

void
ExtrudeStackedAttributes::SetExtentMinima(const doubleVector &extentMinima_)
{
    extentMinima = extentMinima_;
    Select(ID_extentMinima, (void *)&extentMinima);
}

void
ExtrudeStackedAttributes::SetExtentMaxima(const doubleVector &extentMaxima_)
{
    extentMaxima = extentMaxima_;
    Select(ID_extentMaxima, (void *)&extentMaxima);
}

void
ExtrudeStackedAttributes::SetExtentScale(const doubleVector &extentScale_)
{
    extentScale = extentScale_;
    Select(ID_extentScale, (void *)&extentScale);
}

void
ExtrudeStackedAttributes::SetVariableDisplay(ExtrudeStackedAttributes::VariableDisplayType variableDisplay_)
{
    variableDisplay = variableDisplay_;
    Select(ID_variableDisplay, (void *)&variableDisplay);
}

void
ExtrudeStackedAttributes::SetLength(double length_)
{
    length = length_;
    Select(ID_length, (void *)&length);
}

void
ExtrudeStackedAttributes::SetSteps(int steps_)
{
    steps = steps_;
    Select(ID_steps, (void *)&steps);
}

void
ExtrudeStackedAttributes::SetPreserveOriginalCellNumbers(bool preserveOriginalCellNumbers_)
{
    preserveOriginalCellNumbers = preserveOriginalCellNumbers_;
    Select(ID_preserveOriginalCellNumbers, (void *)&preserveOriginalCellNumbers);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

const double *
ExtrudeStackedAttributes::GetAxis() const
{
    return axis;
}

double *
ExtrudeStackedAttributes::GetAxis()
{
    return axis;
}

bool
ExtrudeStackedAttributes::GetByVariable() const
{
    return byVariable;
}

const std::string &
ExtrudeStackedAttributes::GetDefaultVariable() const
{
    return defaultVariable;
}

std::string &
ExtrudeStackedAttributes::GetDefaultVariable()
{
    return defaultVariable;
}

const stringVector &
ExtrudeStackedAttributes::GetScalarVariableNames() const
{
    return scalarVariableNames;
}

stringVector &
ExtrudeStackedAttributes::GetScalarVariableNames()
{
    return scalarVariableNames;
}

const stringVector &
ExtrudeStackedAttributes::GetVisualVariableNames() const
{
    return visualVariableNames;
}

stringVector &
ExtrudeStackedAttributes::GetVisualVariableNames()
{
    return visualVariableNames;
}

const doubleVector &
ExtrudeStackedAttributes::GetExtentMinima() const
{
    return extentMinima;
}

doubleVector &
ExtrudeStackedAttributes::GetExtentMinima()
{
    return extentMinima;
}

const doubleVector &
ExtrudeStackedAttributes::GetExtentMaxima() const
{
    return extentMaxima;
}

doubleVector &
ExtrudeStackedAttributes::GetExtentMaxima()
{
    return extentMaxima;
}

const doubleVector &
ExtrudeStackedAttributes::GetExtentScale() const
{
    return extentScale;
}

doubleVector &
ExtrudeStackedAttributes::GetExtentScale()
{
    return extentScale;
}

ExtrudeStackedAttributes::VariableDisplayType
ExtrudeStackedAttributes::GetVariableDisplay() const
{
    return VariableDisplayType(variableDisplay);
}

double
ExtrudeStackedAttributes::GetLength() const
{
    return length;
}

int
ExtrudeStackedAttributes::GetSteps() const
{
    return steps;
}

bool
ExtrudeStackedAttributes::GetPreserveOriginalCellNumbers() const
{
    return preserveOriginalCellNumbers;
}

///////////////////////////////////////////////////////////////////////////////
// Select property methods
///////////////////////////////////////////////////////////////////////////////

void
ExtrudeStackedAttributes::SelectAxis()
{
    Select(ID_axis, (void *)axis, 3);
}

void
ExtrudeStackedAttributes::SelectDefaultVariable()
{
    Select(ID_defaultVariable, (void *)&defaultVariable);
}

void
ExtrudeStackedAttributes::SelectScalarVariableNames()
{
    Select(ID_scalarVariableNames, (void *)&scalarVariableNames);
}

void
ExtrudeStackedAttributes::SelectVisualVariableNames()
{
    Select(ID_visualVariableNames, (void *)&visualVariableNames);
}

void
ExtrudeStackedAttributes::SelectExtentMinima()
{
    Select(ID_extentMinima, (void *)&extentMinima);
}

void
ExtrudeStackedAttributes::SelectExtentMaxima()
{
    Select(ID_extentMaxima, (void *)&extentMaxima);
}

void
ExtrudeStackedAttributes::SelectExtentScale()
{
    Select(ID_extentScale, (void *)&extentScale);
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: ExtrudeStackedAttributes::GetFieldName
//
// Purpose:
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
ExtrudeStackedAttributes::GetFieldName(int index) const
{
    switch (index)
    {
    case ID_axis:                        return "axis";
    case ID_byVariable:                  return "byVariable";
    case ID_defaultVariable:             return "defaultVariable";
    case ID_scalarVariableNames:         return "scalarVariableNames";
    case ID_visualVariableNames:         return "visualVariableNames";
    case ID_extentMinima:                return "extentMinima";
    case ID_extentMaxima:                return "extentMaxima";
    case ID_extentScale:                 return "extentScale";
    case ID_variableDisplay:             return "variableDisplay";
    case ID_length:                      return "length";
    case ID_steps:                       return "steps";
    case ID_preserveOriginalCellNumbers: return "preserveOriginalCellNumbers";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::GetFieldType
//
// Purpose:
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeGroup::FieldType
ExtrudeStackedAttributes::GetFieldType(int index) const
{
    switch (index)
    {
    case ID_axis:                        return FieldType_doubleArray;
    case ID_byVariable:                  return FieldType_bool;
    case ID_defaultVariable:             return FieldType_string;
    case ID_scalarVariableNames:         return FieldType_stringVector;
    case ID_visualVariableNames:         return FieldType_stringVector;
    case ID_extentMinima:                return FieldType_doubleVector;
    case ID_extentMaxima:                return FieldType_doubleVector;
    case ID_extentScale:                 return FieldType_doubleVector;
    case ID_variableDisplay:             return FieldType_enum;
    case ID_length:                      return FieldType_double;
    case ID_steps:                       return FieldType_int;
    case ID_preserveOriginalCellNumbers: return FieldType_bool;
    default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::GetFieldTypeName
//
// Purpose:
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
ExtrudeStackedAttributes::GetFieldTypeName(int index) const
{
    switch (index)
    {
    case ID_axis:                        return "doubleArray";
    case ID_byVariable:                  return "bool";
    case ID_defaultVariable:             return "string";
    case ID_scalarVariableNames:         return "stringVector";
    case ID_visualVariableNames:         return "stringVector";
    case ID_extentMinima:                return "doubleVector";
    case ID_extentMaxima:                return "doubleVector";
    case ID_extentScale:                 return "doubleVector";
    case ID_variableDisplay:             return "enum";
    case ID_length:                      return "double";
    case ID_steps:                       return "int";
    case ID_preserveOriginalCellNumbers: return "bool";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: ExtrudeStackedAttributes::FieldsEqual
//
// Purpose:
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
ExtrudeStackedAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const ExtrudeStackedAttributes &obj = *((const ExtrudeStackedAttributes*)rhs);
    bool retval = false;
    switch (index_)
    {
    case ID_axis:
        {  // new scope
        // Compare the axis arrays.
        bool axis_equal = true;
        for(int i = 0; i < 3 && axis_equal; ++i)
            axis_equal = (axis[i] == obj.axis[i]);

        retval = axis_equal;
        }
        break;
    case ID_byVariable:
        {  // new scope
        retval = (byVariable == obj.byVariable);
        }
        break;
    case ID_defaultVariable:
        {  // new scope
        retval = (defaultVariable == obj.defaultVariable);
        }
        break;
    case ID_scalarVariableNames:
        {  // new scope
        retval = (scalarVariableNames == obj.scalarVariableNames);
        }
        break;
    case ID_visualVariableNames:
        {  // new scope
        retval = (visualVariableNames == obj.visualVariableNames);
        }
        break;
    case ID_extentMinima:
        {  // new scope
        retval = (extentMinima == obj.extentMinima);
        }
        break;
    case ID_extentMaxima:
        {  // new scope
        retval = (extentMaxima == obj.extentMaxima);
        }
        break;
    case ID_extentScale:
        {  // new scope
        retval = (extentScale == obj.extentScale);
        }
        break;
    case ID_variableDisplay:
        {  // new scope
        retval = (variableDisplay == obj.variableDisplay);
        }
        break;
    case ID_length:
        {  // new scope
        retval = (length == obj.length);
        }
        break;
    case ID_steps:
        {  // new scope
        retval = (steps == obj.steps);
        }
        break;
    case ID_preserveOriginalCellNumbers:
        {  // new scope
        retval = (preserveOriginalCellNumbers == obj.preserveOriginalCellNumbers);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
//  Method: ExtrudeStackedAttributes::addVariable
//
//  Purpose: adds a variable (assuming at the end)
//
//  Programmer: Allen Sanderson
//  Creation:   August 31, 2023
//
//  Note: Taken largely from Parallel Coordinates plot.
//
// ****************************************************************************

void
ExtrudeStackedAttributes::addVariable(const std::string &variableName_)
{
    InsertVariable(variableName_, scalarVariableNames.size());
}

// ****************************************************************************
//  Method: ExtrudeStackedAttributes::InsertVariable
//
//  Purpose: Inserts an variable at a given index;
//
//  Programmer: Allen Sanderson
//  Creation:   August 31, 2023
//
//  Note: Taken largely from Parallel Coordinates plot.
//
// ****************************************************************************

void
ExtrudeStackedAttributes::InsertVariable(const std::string &variableName_, const int index)
{
    std::string newVariableName = variableName_;

    size_t curVariableCount = scalarVariableNames.size();
    size_t variableOrdinal;
    double saveExtentMin, saveExtentMax, saveExtentScale;

    stringVector::iterator svariableNamesIt;
    stringVector::iterator vvariableNamesIt;
    doubleVector::iterator extentMinIt;
    doubleVector::iterator extentMaxIt;
    doubleVector::iterator extentScaleIt;

    for (variableOrdinal = 0; variableOrdinal < curVariableCount; variableOrdinal++)
    {
        if (scalarVariableNames[variableOrdinal] == newVariableName)
            break;
    }

    if (variableOrdinal < curVariableCount)
    {
        saveExtentMin    = extentMinima[variableOrdinal];
        saveExtentMax    = extentMaxima[variableOrdinal];
        saveExtentScale  = extentScale[variableOrdinal];

        svariableNamesIt = scalarVariableNames.begin() + variableOrdinal;
        vvariableNamesIt = visualVariableNames.begin() + variableOrdinal;
        extentMinIt      = extentMinima       .begin() + variableOrdinal;
        extentMaxIt      = extentMaxima       .begin() + variableOrdinal;
        extentScaleIt    = extentScale        .begin() + variableOrdinal;

        scalarVariableNames.erase(svariableNamesIt);
        visualVariableNames.erase(vvariableNamesIt);
        extentMinima.erase(extentMinIt);
        extentMaxima.erase(extentMaxIt);
        extentScale .erase(extentScaleIt);
    }
    else
    {
        saveExtentMin   = -1e+37;
        saveExtentMax   = +1e+37;
        saveExtentScale = 1.0;
    }

    size_t insertOrdinal;
    if( 0 <= index && index <= scalarVariableNames.size() )
        insertOrdinal = index;
    else
        insertOrdinal = scalarVariableNames.size();

    svariableNamesIt = scalarVariableNames.begin() + insertOrdinal;
    vvariableNamesIt = visualVariableNames.begin() + insertOrdinal;
    extentMinIt      = extentMinima       .begin() + insertOrdinal;
    extentMaxIt      = extentMaxima       .begin() + insertOrdinal;
    extentScaleIt    = extentScale        .begin() + insertOrdinal;

    scalarVariableNames.insert(svariableNamesIt, newVariableName);
    visualVariableNames.insert(vvariableNamesIt, newVariableName);
    extentMinima       .insert(extentMinIt,      saveExtentMin);
    extentMaxima       .insert(extentMaxIt,      saveExtentMax);
    extentScale        .insert(extentScaleIt,    saveExtentScale);

    SelectAll();
}

// ****************************************************************************
//  Method: ExtrudeStackedAttributes::DeleteVariable
//
//  Purpose: Deletes an variable (as long as there are enough remaining)
//
//  Programmer: Allen Sanderson
//  Creation:   August 31, 2023
//
//  Note: Taken largely from Parallel Coordinates plot.
//
// ****************************************************************************

void
ExtrudeStackedAttributes::DeleteVariable(const std::string &variableName_,
                                         int minVariableCount)
{
    if ((int)scalarVariableNames.size() <= minVariableCount) return;

    std::string newVariableName = variableName_;

    size_t curVariableCount = scalarVariableNames.size();
    size_t variableOrdinal;

    for (variableOrdinal = 0; variableOrdinal < curVariableCount; variableOrdinal++)
    {
        if (scalarVariableNames[variableOrdinal] == newVariableName) break;
    }

    if (variableOrdinal < curVariableCount)
    {
        visualVariableNames.erase(visualVariableNames.begin() + variableOrdinal);
        scalarVariableNames.erase(scalarVariableNames.begin() + variableOrdinal);
        extentMinima.erase(extentMinima.begin() + variableOrdinal);
        extentMaxima.erase(extentMaxima.begin() + variableOrdinal);
        extentScale .erase(extentScale .begin() + variableOrdinal);

        SelectAll();
    }
}

// ****************************************************************************
//  Method: ExtrudeStackedAttributes::AttributesAreConsistent
//
//  Purpose: Returns true only if (1) all vector attributes are the same 
//           length, (2) all variable names are unique, and (3) the index
//           of the currently displayable variable information in the GUI
//           is in range.
//
//  Programmer: Allen Sanderson
//  Creation:   August 31, 2023
//
// ****************************************************************************

bool
ExtrudeStackedAttributes::AttributesAreConsistent() const
{
    size_t variableNamesSize = scalarVariableNames.size();

    if ((extentMinima.size() != variableNamesSize) ||
        (extentMaxima.size() != variableNamesSize) ||
        (extentScale.size()  != variableNamesSize))
    {
        return false;
    }

    for (size_t i = 0; i < variableNamesSize - 1; i++)
    {
        std::string variableName = scalarVariableNames[i];

        for (size_t j = i + 1; j < variableNamesSize; j++ )
        {
            if (scalarVariableNames[j] == variableName)
                return false;
        }
    }

    return true;
}

